package com.ayoka.ui.member;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.ayoka.Constant;
import com.ayoka.R;
import com.ayoka.base.BaseActivity;
import com.ayoka.bean.UserInformation;
import com.ayoka.bean.WechatPaymentBean;
import com.ayoka.databinding.ActivityOpenMemberBinding;
import com.ayoka.mvp.MemberMVP.IMemberView;
import com.ayoka.mvp.MemberMVP.MemberPresenter;
import com.ayoka.ui.pay.PayActivity;
import com.ayoka.utils.MemberEvent;
import com.jcp.baselibrary.model.ToolBarOptions;
import com.jcp.baselibrary.utils.StringUtil;


/**
 * @author jcp
 * @ClassName: TopicListActivity
 * @Description:
 * @date 2018-12-28 下午4:21:18
 */
public class OpenMemberActivity extends BaseActivity<ActivityOpenMemberBinding, MemberPresenter> implements IMemberView{

    public static void start(Activity activity, int type) {
        Intent intent = new Intent(activity, OpenMemberActivity.class);
        intent.putExtra("Type", type);
        activity.startActivity(intent);
    }

    private  int type;

    @Override
    protected void configIntentValue() {
        Intent intent = getIntent();
        if (intent != null){
            type = intent.getIntExtra("Type", Constant.OpenMember.OPEN_MEMBER);
        }
    }

    @Override
    public int getContentLayout() {
        return R.layout.activity_open_member;
    }

    @Override
    protected void initViews() {
        mDataBinding.tvMemberPrice.setText(StringUtil.formatString(R.string.format_member_price_year, 499));

        mDataBinding.btnOpenMember.setOnClickListener(this);
        if (type == Constant.OpenMember.OPEN_MEMBER){
            mDataBinding.btnOpenMember.setVisibility(View.VISIBLE);
            mDataBinding.btnOpenMember.setText(R.string.open_member);
        } else if (type == Constant.OpenMember.CHECK_RIGHT){
            mDataBinding.btnOpenMember.setVisibility(View.GONE);
        }
    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        ToolBarOptions options = new ToolBarOptions();
        options.navigateId = R.mipmap.icon_back_gold_dark;
        options.backgroundResource = R.color.transparent;
        setCustomToolBar(mDataBinding.customToolbar.toolbar, options);

    }

    @Override
    protected MemberPresenter getPresenter() {
        return new MemberPresenter();
    }

    @Override
    public void onClick(View view) {
        super.onClick(view);
        if (view == mDataBinding.btnOpenMember){
//            PayActivity.start(this, 1234);
            mPresenter.getMemberPaymentData();
            mDataBinding.btnOpenMember.setEnabled(false);
        }
    }

    @Override
    public void onGetMemberPaymentDataSuccess(WechatPaymentBean wechatPaymentBean) {
        if (wechatPaymentBean != null){
            UserInformation.getInstance().user_info.IsVip = 1;
            UserInformation.save();
            MemberEvent.getInstance().notifyMemberStatusChanged();
            OpenMemberSuccessActivity.start(this);
            finish();
        } else {
            mDataBinding.btnOpenMember.setEnabled(true);
        }
    }
}
